/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.pz.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jannek
 */
public abstract class Log {
	private static final boolean DEBUG = true;

	private static PrintStream out = null;

	private static String last = "";
	private static int count = 0;
	private static long nano;

    static {
        setOut(System.out);
    }

    public static void setOut(PrintStream out) {
        if (Log.out != null)
            Log.out.close();
        Log.out = out;
        out.println("LOG STARTED: " + Calendar.getInstance().getTime());
    }

	private static void print(String line) {
        if (!DEBUG)
            return;

		if (nano < System.nanoTime() - 4e9)
			last = "";
        
		if (last.equals(line)) {
			count++;
			return;
		} else {
			nano = System.nanoTime();
			last = line;
			if (count > 0)
				line = " X " + (count + 1) + "\n" + line;
			count = 0;
		}
        out.println(line);
	}

	public static void d(String log) {
		print("LOG: " + log);
	}

	public static void d(boolean log) {
		print("LOG: " + (log ? "true" : "false"));
	}

	public static void d(int log) {
		print("LOG: int " + log);
	}

	public static void d(Exception log) {
		print("LOG: ex " + log.getMessage());
	}

    public static void d(Object o) {
        print("LOG: " + o.toString());
    }
}
